import './login.html';

import { Template } from 'meteor/templating';
import { Message } from '../../components/message/message.js'
Template.App_login_page.events({
  "submit form": function(event, template){
    event.preventDefault();
    let username_jquery = "[name='username']";
  	let password_jquery = "[name='password']";

  	let username = $(username_jquery).val();
  	let password = $(password_jquery).val();

    if (username === '') {
      alert("请输入用户名");
    }
    if (password == '') {
      alert("请输入密码");
    }
    Meteor.loginWithPassword(username, password, function(error){
      if (error) {
                if (error.reason == "Match failed") {
                  alert("密码或其他信息错误");

                return false;
               }
               if (error.reason == "Incorrect password") {
                alert("密码错误");

                return false;
               }
               if (error.reason == "User not found") {
                alert("用户不存在");

                return false;
               }

              }else{

                  FlowRouter.go('App.admin');
                  Message.sendSuccess("登录成功", '');
              }
    });
  }
});
